#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   Bootloader_RequestDownload_0x34_test.py
@Time    :   2022/10/13 10:35:23
@Author  :   Yang Liang
@Version :   1.0
@Contact :   yangliang@chengtech.com
@License :   (C)Copyright 2022-2025
@Desc    :   None
'''

# here put the import lib
from numpy import byte, bytes_, int16
from pytest_assume.plugin import assume
 
import pytest
import time
import requests
from sympy import I
# from sympy import assuming
from commDriver.TS_CAN import *
import allure
import sys
from collections.abc import Iterable

from sqlalchemy import false
sys.dont_write_bytecode = True

SID_0x34_RequestDownload_NRC = [([0x34],[0x7F,0x34,0x13],[0x34]),            
                              ([0x34,0x00],[0x7F,0x34,0x13],[0x34,0x00]),
                              ([0x34,0x00,0x44],[0x7F,0x34,0x13],[0x34,0x00,0x44]),
                              ([0x34,0x00,0x44,0x00,0x05,0x00,0x00,0x00,0x00,0x00],[0x7F,0x34,0x13],[0x34,0x00,0x44,0x00,0x05,0x00,0x00,0x00,0x00,0x00]),
                              ([0x34,0x00,0x33,0x05,0x00,0x00,0x00,0x00,0x00,0x00],[0x7F,0x34,0x13],[0x34,0x00,0x33,0x05,0x00,0x00,0x00,0x00,0x00,0x00]),
                              ([0x34,0x00,0x33,0x05,0x00,0x00,0x00,0x00,0x01],[0x7F,0x34,0x13],[0x34,0x00,0x33,0x05,0x00,0x00,0x00,0x00,0x01]),
                              ([0x34,0x01,0x44,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x01],[0x7F,0x34,0x12],[0x34,0x01,0x44,0x00,0x05,0x00,0x00,0x00,0x00,0x00,0x01]),
                              ([0x34,0x00,0x44,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x01],[0x7F,0x34,0x70],[0x34,0x10,0x44,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x01]),
                              ([0x34,0x10,0x44,0x00,0x03,0x00,0x00,0x00,0x00,0x00],[0x7F,0x34,0x13],[0x34,0x10,0x44,0x00,0x03,0x00,0x00,0x00,0x00,0x00])]  
                              
class Test_RequestDownload_Phy(object):

     ids = ["Request {2}".format(req,resp,binascii.b2a_hex(bytearray(send),' ')) for req,resp,send in SID_0x34_RequestDownload_NRC]
     @allure.severity('minor')
     @allure.description('Test NRC of 0x31 in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     @pytest.mark.parametrize('req,resp,title',SID_0x34_RequestDownload_NRC,ids = ids)
     def test_RequestDownload_NRC_Phy(self,action,Driver,req,resp,title):
          iStep = 1
          time.sleep(1)
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, req, resp, 2, iStep, True)

     @allure.severity('minor')
     @allure.description('Test NRC33 of 0x34 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestDownload_NRC33_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x34,0x00,0x44,0x00,0x7A,0x00,0x00,0x00,0x00,0x28,0x0A], [0x7F,0x34,0x33], 2, iStep, False)

     @allure.severity('minor')
     @allure.description('Test NRC70 of 0x34 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestDownload_NRC70_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x34,0x00,0x44,0x01,0x7A,0x00,0x00,0x00,0x00,0x28,0x0A], [0x7F,0x34,0x70], 2, iStep, True)

     @allure.severity('minor')
     @allure.description('Test NRC12 of 0x34 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestDownload_NRC12_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x34,0x01,0x44,0x01,0x7A,0x00,0x00,0x00,0x00,0x28,0x0A], [0x7F,0x34,0x12], 2, iStep, True)


     @allure.severity('minor')
     @allure.description('Test NRC7F of 0x34 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestDownload_NRC7F_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x34,0x00,0x44,0x00,0x7A,0x00,0x00,0x00,0x00,0x28,0x0A], [0x7F,0x34,0x7F], 3, iStep, True)


     @allure.severity('minor')
     @allure.description('Test NRC31 of 0x34 in programming session in bootloader with physical addressing')
     @allure.testcase('Test cases address:https://chengtech.pingcode.com/testhub/libraries/62a69d6cb35db4f20e37703a/cases')
     def test_RequestDownload_NRC31_Phy(self,Driver,action):
          iStep = 1
          iStep,uds_resp, size = Driver['CAN'].checkReqResp(Driver, [0x34,0x00,0x55,0x00,0x7A,0x00,0x00,0x00,0x00,0x28,0x0A], [0x7F,0x34,0x31], 2, iStep, True)
     